package com.zhuiyun.project.config;

import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * @Description TODO
 * @Author shy
 * @Date 2024/3/10 19:45
 */
@Component
public class RabbitMQCallback implements RabbitTemplate.ConfirmCallback {
    @Resource
    RabbitTemplate rabbitTemplate;
    @PostConstruct
    void init(){
        rabbitTemplate.setConfirmCallback(this);
    }
    /**
     *
     * @Author shy
     * @Date 2024/3/11 11:25
      * @param correlationData   唯一id
     * @param b    是否发送成功
     * @param s    失败原因

     */
    @Override
    public void confirm(CorrelationData correlationData, boolean b, String s) {
        if(b){
            //消息发送成功
            System.out.println("消息发送成功");

        }else {
            //消息发送失败  处理逻辑
            System.out.println("消息处理失败原因");
            System.out.println(s);
        }
    }
}